package com.itheima.operator;

public class OperatorDemo4 {
    public static void main(String[] args) {
        //目标：赋值运算符
        int a = 10;//从右往左看，把10赋给变量a
        System.out.println(a);

        //重点关注：扩展的赋值运算符
        int i = 5;
        int j = 2;
        i+= j;//等价于：i = (i的类型)(i+j);
        System.out.println(i);

        //这种累加有什么用？比如可以用到收红包上
        double m = 9.9;
        int n = 100;
        m+= n;//等价于：m = (double)(m+n);
        System.out.println(m);

        //减法
        int m1 = 22;
        int n1 = 11;
        m1 -= n1;//等价于：m1 = (int)(m1-n2);
        System.out.println(m1);

        int a1 = 10;
        int b1 = 5;
        a1 *=b1;//等价于：a1 = (a1的类型)(a1 * b1);
        System.out.println(a1);

        //还有一个作用：可以自带强制类型转换，不需要自己手动强转
        byte t1 = 110;
        byte t2 = 120;
        //byte t3 = t1 + t2; //报错
        //byte t3 = (byte)(t1 + t2);//其中一种写法
        t1 += t2;//等价于 t1 = (byte)(t1 + t2)  简洁很多
        System.out.println(t1);



    }
}
